/// Includes, system
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <windows.h>
/// Includes, cuda
#include <cublas_v2.h>
#include <cuda.h>
#include "cutil.h"
/// Includes, project
#include "../common/framework.h"
#include "svmClassify.h"
#include "svmClassifyConfig.h"
#include "svmClassifyData.h"

int main( const int argc, const char** argv) {
	svmClassifyConfig * config = new svmClassifyConfig();
	svmClassifyData * testData = new svmClassifyData();
	svmClassify * classifier = new svmClassify(config, testData);
	/// parsing command
	config->parseCommand(argc,argv);
	/// read svm model file
	config->readModel();
	/// read testing file
	testData->readSvm(config->testingFilename);
	/// check whether the dimension of support vector is maches with testing data
	config->checkDimension(testData->nDimension);

	/// CLASSIFY
	classifier->classify();

	int correct = 0;
	for(int i=0;i<testData->nPoints;i++) {
		//if(std::abs(testData->labels[i] - (float)config->classLabels[*(((int*)classifier->result)+i)]) < 0.01f)
		if(testData->labels[i] == config->classLabels[*(reinterpret_cast<int*>(classifier->result)+i)])
			correct++;
	}
	HANDLE hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hStdout,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
	printf("Accuracy: %f% (%d / %d) \n",(float)(correct)*100.0/(float)(testData->nPoints), correct, testData->nPoints);
	SetConsoleTextAttribute(hStdout,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);


	classifier->printClassification();
	/// clean model and testing data
	classifier->cleanResult();
	testData->cleanData();
	config->cleanModel();
	delete config;
	delete testData;
	delete classifier;

	//system("PAUSE");
	return 0;
}